/* describes a world with two buttons
 * classic game and
 * time attack
 */
class WorldMenu extends World {

	/* main menu isn't so fancy */
	assets() {
		return [
			"images/stage_empty.png",
		];
	}

	/* initialize everything */
	start() {

		/* object to transfer data between worlds */
		this.returner = {};

		/* title style */
		let titleStyle = new PIXI.TextStyle({
			fill: "#ff0000",
			fontSize: 70,
			fontWeight: "bold",
		});

		/* title text */
		this.text_title = new PIXI.Text(
			"Mul-Tic-Toe!", titleStyle);
		this.text_title.anchor = {x:0.5, y:1};
		this.text_title.x = width/2;
		this.text_title.y = 100;
		app.stage.addChild(this.text_title);

		/* text style */
		let style = new PIXI.TextStyle({
			fill: "#ff0000",
			fontSize: 30,
		});

		/* play classic button */
		this.button_start = new PIXI.Sprite(
			loader.resources["images/stage_empty.png"].texture
		);
		this.button_start.anchor = {x:0.5, y:0.5};
		this.button_start.x = width/2;
		this.button_start.y = height *2/4;
		app.stage.addChild(this.button_start);

		this.text_friend_start = new PIXI.Text(
			"classic", style);
		this.text_friend_start.anchor = {x:0.5, y:0.5};
		this.text_friend_start.x = this.button_start.x;
		this.text_friend_start.y = this.button_start.y;
		app.stage.addChild(this.text_friend_start);

		/* play time attack button */
		this.button_time = new PIXI.Sprite(
			loader.resources["images/stage_empty.png"].texture
		);
		this.button_time.anchor = {x:0.5, y:0.5};
		this.button_time.x = width/2;
		this.button_time.y = height *3/4;
		app.stage.addChild(this.button_time);

		this.text_time = new PIXI.Text(
			"time attack", style);
		this.text_time.anchor = {x:0.5, y:0.5};
		this.text_time.x = this.button_time.x;
		this.text_time.y = this.button_time.y;
		app.stage.addChild(this.text_time);

	} /* constructor */

	/* handle button pressing */
	update() {

		/* handle input */
		for (let e = 0; e < input.length; e++) {

			/* left click */
			if (input[e].which == 1) {

				/* click point */
				let p = new PIXI.Point(
					input[e].offsetX, input[e].offsetY
				);

				/* start classic */
				if (this.button_start.containsPoint(p)) {
					this.returner.mode = "classic";
					return world_list.indexOf(WorldClassicSelection);
				}

				/* start time */
				if (this.button_time.containsPoint(p)) {
					this.returner.mode = "time";
					return world_list.indexOf(WorldClassicSelection);
				}


			} /* left click */

		} /* handle input */

	} /* update */

} /* world menu */
